﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace eGrocery.ProductDA
{
  public  class CategoryDA 
    {

//        public override ProductEntity.Category SaveObject(string userName, ProductEntity.Category tObject)
//        {
//            #region PROCEDURE
//            /** 
//            CREATE PROCEDURE [dbo].[USP_INS_UPDATE_CATEGORY]  
//(@Category_ID int,  
//@Category_Name varchar(256), 
//@CreationDate datetime,
//@CreatedBy varchar(100),
//@ModificationDate datetime,
//@ModifiedBy varchar(100),
//@IsLive bit)  
//as  
//BEGIN  
//IF (@Category_ID=0)  
//BEGIN  
//INSERT INTO Category (Category_Name,CreationDate,CreatedBy ,ModificationDate,ModifiedBy,IsLive)  
//VALUES(@Category_Name,@CreationDate,@CreatedBy,@ModificationDate,@ModifiedBy,@IsLive)  
//SELECT @@IDENTITY  
//END  
//ELSE  
//BEGIN  
//UPDATE Category SET Category_Name=@Category_Name, CreationDate=@CreationDate,  
//CreatedBy=@CreatedBy,ModificationDate=@ModificationDate,
//ModifiedBy=@ModifiedBy ,IsLive=@IsLive
//WHERE Category_ID=@Category_ID  
//END  
//END
            
//            **/

//            #endregion

//            try
//            {
//                GetNewDBHelper();
//                dbHelper.AddParameter("@Category_ID", tObject.CategoryID);
//                dbHelper.AddParameter("@Category_Name", tObject.CategoryName);
//                dbHelper.AddParameter("@CreationDate", tObject.CreationDate);
//                dbHelper.AddParameter("@CreatedBy", tObject.CreatedBy);
//                dbHelper.AddParameter("@ModificationDate", tObject.ModificationDate);
//                dbHelper.AddParameter("@ModifiedBy", tObject.ModifiedBy);
//                dbHelper.AddParameter("@IsALive", tObject.IsAlive);
//                //dbHelper.ExecuteNonQuery("USP_INS_UPDATE_CATEGORY", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
//                object objID = dbHelper.ExecuteScaler("USP_INS_UPDATE_CATEGORY", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);

//                if (Convert.ToInt32(objID) > 0)

//                    tObject.CategoryID = Convert.ToInt32(objID);

//                LogActivity(userName, string.Format("Product Saved with ID {0}", tObject.CategoryID), tObject);

//            }
            
//            catch (Exception ex)
//            {

//                LogException(userName, ex, tObject);
//                tObject = null;
//                throw new Exception("Error Occured while Saving Product");

//            }
            
           
//            return tObject;
//           // throw new NotImplementedException();
//        }

//        public override bool DeleteObject(string userName, ProductEntity.Category tObject)
//        {
//            try
//            {
//                GetNewDBHelper();
//                dbHelper.AddParameter("@CategoryId", tObject.CategoryID);
//                dbHelper.ExecuteNonQuery("USP_DELETE_CATEGORY", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
//                // throw new NotImplementedException();
//                return tObject.IsLive;

//            }
//            catch
//            {
//                return tObject.IsLive;
//            }   
            
//            //throw new NotImplementedException();
//        }

//        public override List<ProductEntity.Category> GetObjectList(string userName, DateTime fromDate, DateTime toDate)
//        {
//            throw new NotImplementedException();
//        }

//        public override List<ProductEntity.Category> SearchObject(string userName, string SearchText)
//        {
//            try
//            {
//                dbHelper.AddParameter("@SearchText", string.IsNullOrWhiteSpace(SearchText) ? string.Empty : SearchText);
//                var reader = dbHelper.ExecuteReader("USP_SEARCH_CATEGORY", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
//                var list = new List<ProductEntity.Category>();
//                while (reader.Read())
//                {
//                    list.Add(GetCategoryObject(reader, true));
//                }
//                LogActivity(userName, string.Format("Searched Category with text {0}", SearchText), null);
//                return list;
//            }
//            catch (Exception ex)
//            {
//                LogException(userName, ex, null);
//                throw new Exception("Error while searching Category");
//            }
//           // throw new NotImplementedException();
//        }
//        public static ProductEntity.Category GetCategoryObject(IDataReader reader, bool IsFull)
//        {
//            int i = -1;
//            ProductEntity.Category obj = new ProductEntity.Category();
//            if (!reader.IsDBNull(++i))
//                obj.CategoryID = reader.GetInt32(i);
//            if (!reader.IsDBNull(++i))
//                obj.CategoryName = reader.GetString(i);
            
//            if (IsFull)
//            {
//                if (!reader.IsDBNull(++i))
//                    obj.IsAlive = reader.GetBoolean(i);
//            }
//            return obj;
//        }
    }
}
